import request from '@/utils/request'

/* 搜索作者列表 */
export function search(data) {
  // console.log('传给后台', data)
  return request({
    url: 'http://192.168.1.141/bw/Copyrighter/Copyrighter_Search.php', // 'http://rap2api.taobao.org/app/mock/299325/api/search', //
    method: 'post',
    data
  }) // 每个方法返回的都是一个promise对象
}
/* 添加作者*/
export function add(data) {
  console.log('传给后台的数据', data)
  const test = request({
    url: 'http://192.168.1.141/bw/Copyrighter/Copyrighter_add_save.php',
    method: 'post',
    data
  })
  console.log('test', test)
  return test
}
/* 编辑作者 */
export function edit(data) {
  console.log('传给后台的数据', data)
  const test = request({
    url: 'http://192.168.1.141/bw/Copyrighter/Copyrighter_edit_save.php',
    method: 'post',
    data
  })
  console.log('test', test)
  return test
}
/* 上传作者照片 */
export function addphoto(config, formData) {
  const datestamp = Date.now()
  return request({
    url: 'http://192.168.1.141/public/UploadFile.php',
    method: 'post',
    data: {
      remoteFilePath: `/bw/Copyrighter/img/${datestamp}_P.JPG`,
      ...formData,
      ...config
    }
  })
  // console.log('test上传', test)
}

/* 获得作者详情*/
export function detail(data) {
  console.log('传给后台的数据', data)
  const test = request({
    url: 'http://192.168.1.141/bw/Copyrighter/Copyrighter_Detail.php',
    method: 'post',
    data: {
      ID: data
    }

  })
  console.log('详情', test)
  return test
}

/* 删除作者信息--单条*/
export function deletesingle(data) {
  console.log('传给后台的删除数据', data)
  let url = 'http://192.168.1.141/bw/Copyrighter/Copyrighter_delete.php' // 单个删除
  if (data.indexOf(',') > -1) { // 是批量删除
    url = 'http://192.168.1.141/bw/Copyrighter/Copyrighter_batch_delete.php'
  }
  const test = request({
    url,
    method: 'post',
    data: {
      ID: data
    }
  })
  // console.log('删除结果：', test)
  return test
}

